import requests
import re

url = "http://www.weather.com.cn/weather1d/101180101.shtml"
response = requests.get(url)
response.encoding = "utf-8"
# print("response", response)
text = response.text
# print("text", text)
# https://www.manongjc.com/detail/27-fpaxpmidbyloaiw.html 参考的正则表达式
# nameList = re.findall('<span class="name">([\u4e00-\u9fa5]*)</span>', text)
nameList = re.findall('<span class="name">(.*?)</span>', text)
weatherList = re.findall('<span class="weather">(.*?)</span>', text)
wdList = re.findall('<span class="wd">(.*?)</span>', text)
zsList = re.findall('<span class="zs">(.*?)</span>', text)
print(nameList)
print(weatherList)
print(wdList)
print(zsList)
result = zip(nameList, weatherList, wdList, zsList)
print(result)
print("-" * 20)
print([x for x in result])

print("*" * 20)

print(list(zip(nameList, weatherList, wdList, zsList)))
for x in list(zip(nameList, weatherList, wdList, zsList)):
    print(x[0], x[1], x[2], x[3])
# zip 参见 https://c.biancheng.net/view/2237.html

download_image_url = "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"
response = requests.get(download_image_url)
with open("baidu.png", "wb") as w:
    w.write(response.content)
# http://www.codebaoku.com/python3/python3-file-methods.html
